package com.itheima.controller;

import com.itheima.common.CompanyResult;
import com.itheima.common.Result;
import com.itheima.pojo.hm.HmSubjectsTags;
import com.itheima.service.TagsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 *@Parm
 *@ClassName TagsController
 *@Date 2022/1/10 10:21
 */
@RestController
@RequestMapping("/tags")
public class TagsController {
    @Autowired
    private TagsService tagsService;

    @PostMapping
    public CompanyResult add(@RequestBody HmSubjectsTags tags){
        return tagsService.add(tags);
    }

    @GetMapping
    public Result findPage(Integer page,Integer pagesize,String tagName,Integer state,Integer subjectID){
        return tagsService.findPage(page,pagesize,tagName,state,subjectID);
    }

    @PutMapping("/{id}")
    public CompanyResult updateById(@PathVariable Integer id,@RequestBody HmSubjectsTags tags){
        return tagsService.updateById(tags);
    }

    @DeleteMapping("/{id}")
    public CompanyResult deleteById(@PathVariable Integer id,@RequestBody HmSubjectsTags tags){
        return tagsService.deleteById(id);
    }

    @PostMapping("/{id}/{state}")
    public CompanyResult updateByStates(@PathVariable Integer id,@PathVariable Integer state){
        return tagsService.updateByState(id,state);
    }

    @GetMapping("/{id}")
    public HmSubjectsTags findOne(@PathVariable Integer id){
        return tagsService.findOne(id);
    }

}
